#include "logic.h"
#include <stdlib.h>


bool Logic::GetChance(unsigned short param)
{
    if(param >= 100)
    {
        return true;
    }
    else
    {
        if(param > rand()%100)
        {
            return true;
        }
    }
    return false;
}
void Logic::SetRandomPath()
{
    unit->currentTask = new Task(Task::GoTo,unit->x + 100 - rand()%200, unit->y + 100 - rand()%200);
}
void Logic::Think()
{
    if(unit->currentTask == 0)
    {
        GetNewTarget();
    }
}
//void Logic::
void Logic::GetNewTarget()
{
    if(GetChance(unit->search))
    {
        SetRandomPath();
    }
    else
    {
        unit->currentTask = new Task(Task::Stop,0,0);
    }
}
Logic::Logic(BioUnit* Unit)
{
    unit = Unit;
    unit->currentTask= 0;
}
